--
module("UI.Windows.ZhaoHuiPasswordWin", package.seeall)

local UIUtility = require("UI.Utility")
local UIWindow = require("UI.UIWindow").UIWindow
local UIWinMgr = require("UI.UIWinMgr").UIWinMgr
local json = require("cjson")
ZhaoHuiPasswordWin = UIWindow:new()

ZhaoHuiPasswordWin.name = "ZhaoHuiPasswordWin"


function ZhaoHuiPasswordWin:Init()
    local t = self.Container.transform

    self.close_btn = UIUtility.GetChildTransform("close_btn", t, true)
    self:BindEvents()

    self.zhaohui_zhanghao_input = UIUtility.FindContorl("UIInput", "zhaohui_zhanghao_input", t)
    self.zhaohui_yzm_input = UIUtility.FindContorl("UIInput", "zhaohui_yzm_input", t)
    self.zhaohui_new_password_input = UIUtility.FindContorl("UIInput", "zhaohui_new_password_input", t)
    self.zhaohui_new_password_input_2 = UIUtility.FindContorl("UIInput", "zhaohui_queren_password_input", t)

    self.Confirm_btn = UIUtility.GetChildTransform("Confirm_btn", t, true)
    self.zhaohui_huoqu_btn = UIUtility.GetChildTransform("zhaohui_huoqu_btn", t, true)


    UIHelper.BindUIEvnet("Click", function()
        --获取验证码
        require("NetWork.NetHttp").SendRequest(
            require("Module.ConfigModule").ConfigModule.SessionUrl ..
            "/byr/sms/sendCode?phoneNumber=" .. self.zhaohui_zhanghao_input.value
            .. "&uuid=" .. UnityEngine.SystemInfo.deviceUniqueIdentifier, function(ok, data)
                if ok then
                    print("获取验证码" .. stringify(data))
                    UIWinMgr:OpenTextNotice("获取验证码成功")
                else
                    print("获取验证码失败" .. stringify(data))
                    UIWinMgr:OpenTextNotice("获取验证码失败")
                end
            end)
    end, self.zhaohui_huoqu_btn.gameObject)


    UIHelper.BindUIEvnet("Click", function()
        if self.zhaohui_new_password_input.value ~= self.zhaohui_new_password_input_2.value then
            UIWinMgr:OpenTextNotice("两次输入的密码不一致")
            return
        end
        if self.zhaohui_zhanghao_input.value == "" then
            UIWinMgr:OpenTextNotice("请输入手机号")
            return
        end
        if self.zhaohui_yzm_input.value == "" then
            UIWinMgr:OpenTextNotice("请输入真实姓名")
            return
        end
        --请求找回密码
        local zhaohuiJson = string.format(
            '{"phone": "%s","name":"%s","password": "%s"}',
            self.zhaohui_zhanghao_input.value,
            self.zhaohui_yzm_input.value,
            self.zhaohui_new_password_input.value
        )


        require("NetWork.NetHttp").SendPostRequest("/aut/buyer/restPassword", function(ok, data)
            if ok then
                UIWinMgr:OpenTextNotice("新密码设置成功")
            else
                UIWinMgr:OpenTextNotice(data.msg)
            end
        end, zhaohuiJson)
    end, self.Confirm_btn.gameObject)
end

function ZhaoHuiPasswordWin:OnShow()

end

function ZhaoHuiPasswordWin:OnClose()

end

function ZhaoHuiPasswordWin:BindEvents()
    UIHelper.BindUIEvnet("Click", function()
        self:Close(1)
    end, self.close_btn.gameObject)
end
